package com.example.demo.service.impl;

import com.example.demo.domain.Grade;
import com.example.demo.mapper.GradeMapper;
import com.example.demo.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GradeServiceImpl implements GradeService {

    private GradeMapper gradeMapper;

    @Autowired
    public void setGradeMapper(GradeMapper gradeMapper){
        this.gradeMapper = gradeMapper;
    }

    /**
     * 查询成绩列表
     * @return
     */
    @Override
    public List<Grade> findAll(Integer pageNum, Integer pageSize) {
        return gradeMapper.findAll(pageNum, pageSize);
    }

    /**
     * 查询总记录数
     * @return
     */
    @Override
    public Integer findTotalRecord() {
        return gradeMapper.findTotalRecord();
    }

    @Override
    public Integer findTotalRecordByCid(Integer cid) {
        return gradeMapper.findTotalRecordByCid(cid);
    }

    /**
     * 删除成绩信息
     * @param id
     * @return
     */
    @Override
    public boolean delete(int id,String courseNo) {

        int row = gradeMapper.delete(id,courseNo);
        if(row > 0){
            return true;
        }
        return false;
    }

    /**
     * 添加成绩信息
     * @param grade
     * @return
     */
    @Override
    public boolean add(Grade grade) {
        int row = gradeMapper.add(grade);
        if(row > 0){
            return true;
        }
        return false;
    }

    /**
     * 根据id和courseNo去查找grade
     * @param id
     * @param courseNo
     * @return
     */
    @Override
    public Grade findGradeByIdAndNo(int id, String courseNo) {
        return gradeMapper.findGradeByIdAndNo(id,courseNo);
    }

    @Override
    public boolean update(Grade grade) {
        int row = gradeMapper.update(grade);
        if(row > 0){
            return true;
        }
        return false;
    }



    @Override
    public Integer findNumByCid(Integer cid) {
        return gradeMapper.findNumByCid(cid);
    }
}
